//
//  CalculatePriceViewController.m
//  EMMApp
//
//  Created by Mac on 16/7/1.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "CalculatePriceViewController.h"

/** ViewController
 *
 *  ViewController导入.h文件
 */
#import "LendingRateViewController.h"
#import "ShoufuViewController.h"
#import "PriceResultViewController.h"
#import "EMMTouristsViewController.h"

/** Cell
 *
 *  Cell导入.h文件
 */
#import "AddSubscriptionCell.h"

/** View
 *
 *  View导入.h文件
 */
#import "PromptBoxView.h"


/** Api
 *
 *  Api导入.h文件
 */
#import "GetCalculatePriceApi.h"
#import "CustomerList.h"

@interface CalculatePriceViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

/**
 *  是否有客户 - YES可选择 -NO不能选择
 */
@property (nonatomic, assign) BOOL isseleFals;

/**
 *  列表左侧显示数组
 */
@property (nonatomic, strong) NSMutableArray *grouparr0;

/**
 *  二级列表是否展开状态
 */
@property (nonatomic, strong) NSMutableArray *selectedArr;

/**
 *  存对应的数据字段
 */
@property (nonatomic, strong) NSMutableDictionary *calculateDic;

/**
 *  创建UITableView 命名:calculatePriceTableView
 */
@property (nonatomic, strong) UITableView *calculatePriceTableView;

/**
 *  是否将算价结果,标记为此人的意向房源
 */
@property (nonatomic, strong) NSString *isSeleId;

/**
 *  客户id
 */
@property (nonatomic, strong) NSString *customerId;

/**
 *  客户名称输入框
 */
@property (nonatomic, strong) UITextField *khTextField;

/**
 *  字段 - 客户姓名
 */
@property (nonatomic, strong) NSString *khString;

/**
 *  客户联系电话输入框
 */
@property (nonatomic, strong) UITextField *phonTextField;

/**
 *  字段 - 联系电话
 */
@property (nonatomic, strong) NSString *phonString;

/**
 *  总价输入框
 */
@property (nonatomic, strong) UITextField *totalAmountTextField;

/**
 *  首付输入框
 */
@property (nonatomic, strong) UITextField *firstPayTextField;

/**
 *  字段 - 首付
 */
@property (nonatomic, strong) NSString *firstPay;

/**
 *  字段 - 贷款类型名称
 */
@property (nonatomic, strong) NSString *loanTypeName;

/**
 *  字段 - 贷款类型Id
 */
@property (nonatomic, strong) NSString *loanType;

/**
 *  公积金贷款输入框
 */
@property (nonatomic, strong) UITextField *fundLoanTextField;

/**
 *  字段 - 公积金贷款
 */
@property (nonatomic, strong) NSString *fundLoan;

/**
 *  商业贷款输入框
 */
@property (nonatomic, strong) UITextField *businessLoanTextField;

/**
 *  字段 - 商业贷款类型
 */
@property (nonatomic, strong) NSString *businessLoan;

/**
 *  字段 - 贷款利率
 */
@property (nonatomic, strong) NSString *loanRate;

/**
 *  字段 - 公积金贷款利率
 */
@property (nonatomic, strong) NSString *fundLoanRate;

/**
 *  字段 - 商业贷款利率
 */
@property (nonatomic, strong) NSString *businessLoanRate;

/**
 *  字段 - 贷款年限
 */
@property (nonatomic, strong) NSString *loanLifeName;

/**
 *  字段 - 贷款年限id
 */
@property (nonatomic, strong) NSString *loanLife;

/**
 *  字段 - 贷款倍数
 */
@property (nonatomic, strong) NSString *beishuString;

@end

@implementation CalculatePriceViewController

#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatNavigationController];
    self.view.backgroundColor = [UIColor whiteColor];
    _calculateDic = [[NSMutableDictionary alloc] init];
    _selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",nil];
    _calculatePriceTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight-70) style:UITableViewStylePlain];
    _calculatePriceTableView.delegate = self;
    _calculatePriceTableView.dataSource = self;
    _calculatePriceTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _calculatePriceTableView.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
    _calculatePriceTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_calculatePriceTableView];
    [self initDataSource];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(10, EMM_HEIGHT-70-SafeAreaTopHeight, EMM_WIDTH-20, 50);
    [btn setTitle:@"开始计算" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn addTarget:self action:@selector(startButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 4;
    [self.view addSubview:btn];
    _totalAmount = [NSString stringWithFormat:@"%.2lf",[_getHousesDetail.totalAmount floatValue]*10000];
    _isseleFals = YES;
    _customerId = nil;
    _isSeleId = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 导航调用方法
- (void)creatNavigationController {
    [self updateNavBar];
    self.navigationItem.title = @"算价";
    [self configLeftBtn];
}

#pragma mark - 生命周期函数调用方法
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

#pragma mark - 列表左侧显示数据初始化
/**
 *  功能描述：
 *  列表左侧显示数据初始化
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
-(void)initDataSource {
    _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                 @"房源总价",@"首付",@"贷款类型",@"公积金贷款",@"商业贷款",
                 @"贷款利率",@"商业贷款利率",@"公积金贷款利率", @"贷款年限",nil];
    [_calculateDic setValue:_grouparr0 forKey:@"0"];
}

#pragma mark - UITableView代理
/**
 *  功能描述：
 *  UITabelView 代理方法
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
//返回几个表头
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

//每一个表头下返回几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([_selectedArr containsObject:string]) {
        NSArray *array1 = _calculateDic[string];
        return array1.count;
    }
    return 0;
}

//设置表头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}

//Section Footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 5)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

//设置view，将替代titleForHeaderInSection方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, tableView.frame.size.width-20, 50)];
    titleLabel.text =  [  _getHousesDetail.housesName stringByReplacingOccurrencesOfString:@"-->"withString:@"-"];
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
    [view addSubview:titleLabel];
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, EMM_WIDTH, 50);
    button.tag = 100+section;
    //    [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    view.backgroundColor = [UIColor colorFromHexCode:@"#fff5e9"];
    UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 2, 30)];
    sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [view addSubview:sLabel6];
    
    UIImageView *upImageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 15, 25, 15)];
    //    [view addSubview:upImageView];
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([_selectedArr containsObject:string]) {
        upImageView.image = [UIImage imageNamed:@"sanjt_down"];
    }else {
        upImageView.image = [UIImage imageNamed:@"sanjt_up"];
    }
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        return 60;
    }
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    NSLog(@"%@",indexStr);
    static NSString *CellIdentifier = @"AddSubscriptionCell";
    AddSubscriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"AddSubscriptionCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([_selectedArr containsObject:indexStr]) {
        cell.titleLabel.text = _calculateDic[indexStr][indexPath.row];
    }
    
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [cell addSubview:lineImage];
    if (indexPath.row == 0) {
        UIButton *seleBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        seleBtn.frame = CGRectMake(EMM_WIDTH -35, 10, 30, 30);
        [seleBtn addTarget:self action:@selector(seleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:seleBtn];
        
        _khTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, EMM_WIDTH-100-30, 30)];
        _khTextField.delegate = self;
        _khTextField.returnKeyType =UIReturnKeyDone;
        _khTextField.textAlignment = NSTextAlignmentRight;
        _khTextField.font = [UIFont systemFontOfSize:15];
        [cell addSubview:_khTextField];
        if ([_isSeleId isEqualToString:@"1"]) {
            _khTextField.userInteractionEnabled = NO;
            [seleBtn setImage:[[UIImage imageNamed:@"cha_03"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        }else {
            [seleBtn setImage:[[UIImage imageNamed:@"cha_05"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            _khTextField.userInteractionEnabled = YES;
        }
        if ([NSString isStringEmpty2:_khString] == YES) {
            _khTextField.placeholder = @"请输入";
        }else {
            _khTextField.text = _khString;
        }
    } else if (indexPath.row == 1) {
        _phonTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, EMM_WIDTH-100-10, 30)];
        _phonTextField.delegate = self;
        _phonTextField.returnKeyType =UIReturnKeyDone;
        _phonTextField.textAlignment = NSTextAlignmentRight;
        _phonTextField.font = [UIFont systemFontOfSize:15];
        _phonTextField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
        [cell addSubview:_phonTextField];
        if ([_isSeleId isEqualToString:@"1"]) {
            _phonTextField.userInteractionEnabled = NO;
        }else {
            _phonTextField.userInteractionEnabled = YES;
        }
        if ([NSString isStringEmpty2:_phonString] == YES) {
            _phonTextField.placeholder = @"请输入";
        }else {
            _phonTextField.text = _phonString;
        }
    } else if (indexPath.row == 2) {
        cell.subTiltleTF.hidden = YES;
        
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
        
        CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
        label.textAlignment = NSTextAlignmentRight;
        label.text = @"元";
        label.font = [UIFont systemFontOfSize:15];
        [cell addSubview:label];
        _totalAmountTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
        _totalAmountTextField.delegate = self;
        _totalAmountTextField.returnKeyType =UIReturnKeyDone;
        _totalAmountTextField.textAlignment = NSTextAlignmentRight;
        _totalAmountTextField.font = [UIFont systemFontOfSize:15];
        _totalAmountTextField.keyboardType = UIKeyboardTypeDecimalPad;
        [cell addSubview:_totalAmountTextField];
        if ([NSString isStringEmpty2:_totalAmount] == YES) {
            _totalAmountTextField.placeholder = @"请输入";
        } else {
            _totalAmountTextField.text = _totalAmount;
        }
    } else if (indexPath.row == 3) {
        cell.subTiltleTF.hidden = YES;
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
        CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
        label.textAlignment = NSTextAlignmentRight;
        label.text = @"元";
        label.font = [UIFont systemFontOfSize:15];
        [cell addSubview:label];
        UILabel *firstPayLabel = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
        firstPayLabel.textAlignment = NSTextAlignmentRight;
        firstPayLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:firstPayLabel];
        if ([NSString isStringEmpty2:_firstPay] == YES) {
        } else {
            firstPayLabel.text = _firstPay;
        }
        UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, EMM_WIDTH, 10)];
        v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
        [cell addSubview:v1];
    } else if (indexPath.row == 4) {
        cell.subTitleLabel.hidden = NO;
        cell.btn_qiaoJImageV.hidden = NO;
        cell.subTiltleTF.hidden = YES;
        if ([NSString isStringEmpty2:_loanTypeName] == YES) {
            cell.subTitleLabel.text = @"未选择";
            cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            
        } else {
            cell.subTitleLabel.text = _loanTypeName;
        }
    } else {
        if ([NSString isStringEmpty:_loanTypeName] == NO) {
            if ([_loanTypeName isEqualToString:@"组合贷款"]) {
                if (indexPath.row == 5) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _fundLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _fundLoanTextField.delegate = self;
                    _fundLoanTextField.returnKeyType =UIReturnKeyDone;
                    _fundLoanTextField.textAlignment = NSTextAlignmentRight;
                    _fundLoanTextField.font = [UIFont systemFontOfSize:15];
                    _fundLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                    [cell addSubview:_fundLoanTextField];
                    if ([NSString isStringEmpty2:_fundLoan] == YES) {
                        _fundLoanTextField.placeholder = @"请输入";
                        
                    }else {
                        _fundLoanTextField.text = _fundLoan;
                    }
                    
                } else if (indexPath.row == 6) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _businessLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _businessLoanTextField.delegate = self;
                    _businessLoanTextField.returnKeyType =UIReturnKeyDone;
                    _businessLoanTextField.textAlignment = NSTextAlignmentRight;
                    _businessLoanTextField.font = [UIFont systemFontOfSize:15];
                    _businessLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                    [cell addSubview:_businessLoanTextField];
                    if ([NSString isStringEmpty2:_businessLoan] == YES) {
                        _businessLoanTextField.placeholder = @"请输入";
                    }else {
                        _businessLoanTextField.text = _businessLoan;
                    }
                    
                } else if (indexPath.row == 7) {
                    lineImage.hidden = YES;
                    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10)];
                    v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
//                    [cell addSubview:v1];
                    
                    UIImageView *lineIm = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                    lineIm.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                    [cell addSubview:lineIm];
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;
                    cell.subTiltleTF.hidden = YES;
                    if ([NSString isStringEmpty2:_loanRate] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    } else {
                        cell.subTitleLabel.text = _loanRate;
                    }
                    
                } else if (indexPath.row == 8) {
                    if ([NSString isStringEmpty2:_businessLoanRate] == YES) {
                        cell.subtitleOneLable.text = @"%";
                    } else {
                        NSString *s = @"%";
                        cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_businessLoanRate,s];
                    }
                    
                } else if (indexPath.row == 9) {
                    if ([NSString isStringEmpty2:_fundLoanRate] == YES) {
                        cell.subtitleOneLable.text = @"%";
                    } else {
                        NSString *s = @"%";
                        cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_fundLoanRate,s];
                    }
                    
                } else if (indexPath.row == 10) {
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;
                    cell.subTiltleTF.hidden = YES;
                    
                    if ([NSString isStringEmpty2:_loanLifeName] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    } else {
                        cell.subTitleLabel.text = _loanLifeName;
                    }
                }
            } else if ([_loanTypeName isEqualToString:@"公积金贷款"]) {
                if (indexPath.row == 5) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _fundLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _fundLoanTextField.delegate = self;
                    _fundLoanTextField.returnKeyType =UIReturnKeyDone;
                    _fundLoanTextField.textAlignment = NSTextAlignmentRight;
                    _fundLoanTextField.font = [UIFont systemFontOfSize:15];
                    _fundLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                    [cell addSubview:_fundLoanTextField];
                    if ([NSString isStringEmpty2:_fundLoan] == YES) {
                        _fundLoanTextField.placeholder = @"请输入";
                        
                    }else {
                        _fundLoanTextField.text = _fundLoan;
                    }
                    
                }else if (indexPath.row == 6){
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;

                    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10)];
                    v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
//                    [cell addSubview:v1];
                    if ([NSString isStringEmpty2:_loanRate] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanRate;
                    }
                }else if (indexPath.row == 7) {
                    
                    if ([NSString isStringEmpty2:_fundLoanRate] == YES) {
                        cell.subtitleOneLable.text = @"%";
                    }else {
                        NSString *s = @"%";
                        cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_fundLoanRate,s];
                    }
                    
                }else if (indexPath.row == 8) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;

                    if ([NSString isStringEmpty2:_loanLifeName] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanLifeName;
                    }
                }
            }else if ([_loanTypeName isEqualToString:@"商业贷款"]) {
                if (indexPath.row == 5) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _businessLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _businessLoanTextField.delegate = self;
                    _businessLoanTextField.returnKeyType =UIReturnKeyDone;
                    _businessLoanTextField.textAlignment = NSTextAlignmentRight;
                    _businessLoanTextField.font = [UIFont systemFontOfSize:15];
                    _businessLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                    [cell addSubview:_businessLoanTextField];
                    if ([NSString isStringEmpty2:_businessLoan] == YES) {
                        _businessLoanTextField.placeholder = @"请输入";
                    }else {
                        _businessLoanTextField.text = _businessLoan;
                    }
                    
                }else if (indexPath.row == 6) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;
                    lineImage.hidden = YES;
                    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10)];
                    v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
//                    [cell addSubview:v1];
                    
                    UIImageView *lineIm = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                    lineIm.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                    [cell addSubview:lineIm];
                    
                    if ([NSString isStringEmpty2:_loanRate] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanRate;
                    }
                }else if (indexPath.row == 7) {
                    
                    if ([NSString isStringEmpty2:_businessLoanRate] == YES) {
                        cell.subtitleOneLable.text = @"%";
                    }else {
                        NSString *s = @"%";
                        cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_businessLoanRate,s];
                    }
                }else if (indexPath.row == 8) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;

                    if ([NSString isStringEmpty2:_loanLifeName] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanLifeName;
                    }
                }
            }else {
                if (indexPath.row == 5) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _fundLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _fundLoanTextField.delegate = self;
                    _fundLoanTextField.returnKeyType =UIReturnKeyDone;
                    _fundLoanTextField.textAlignment = NSTextAlignmentRight;
                    _fundLoanTextField.font = [UIFont systemFontOfSize:15];
                    _fundLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                    [cell addSubview:_fundLoanTextField];
                    if ([NSString isStringEmpty2:_fundLoan] == YES) {
                        _fundLoanTextField.placeholder = @"请输入";
                        
                    }else {
                        _fundLoanTextField.text = _fundLoan;
                    }
                }else if (indexPath.row == 6) {
                    cell.subTiltleTF.hidden = YES;
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                    
                    CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                    label.textAlignment = NSTextAlignmentRight;
                    label.text = @"元";
                    label.font = [UIFont systemFontOfSize:15];
                    [cell addSubview:label];
                    
                    _businessLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                    _businessLoanTextField.delegate = self;
                    _businessLoanTextField.returnKeyType =UIReturnKeyDone;
                    _businessLoanTextField.textAlignment = NSTextAlignmentRight;
                    _businessLoanTextField.font = [UIFont systemFontOfSize:15];
                    _businessLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;

                    [cell addSubview:_businessLoanTextField];

                    if ([NSString isStringEmpty2:_businessLoan] == YES) {
                        _businessLoanTextField.placeholder = @"请输入";
                    }else {
                        _businessLoanTextField.text = _businessLoan;
                    }
                    
                }else if (indexPath.row == 7) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;
                    lineImage.hidden = YES;
                    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10)];
                    v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
//                    [cell addSubview:v1];
                    
                    UIImageView *lineIm = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                    lineIm.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                    [cell addSubview:lineIm];
                    
                    if ([NSString isStringEmpty2:_loanRate] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanRate;
                    }
                    
                }else if (indexPath.row == 8) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.danweiLabel.hidden = NO;
                    cell.danweiLabel.text = @"%";
                    
                    if ([NSString isStringEmpty2:_businessLoanRate] == YES) {
                    }else {
                        cell.subTitleLabel.text = _businessLoanRate;
                    }
                    
                    
                }else if (indexPath.row == 9) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.danweiLabel.hidden = NO;
                    cell.danweiLabel.text = @"%";
                    
                    if ([NSString isStringEmpty2:_fundLoanRate] == YES) {
                    }else {
                        cell.subTitleLabel.text = _fundLoanRate;
                    }
                }else if (indexPath.row == 10) {
                    cell.subTiltleTF.hidden = YES;
                    cell.subTitleLabel.hidden = NO;
                    cell.btn_qiaoJImageV.hidden = NO;

                    if ([NSString isStringEmpty2:_loanLifeName] == YES) {
                        cell.subTitleLabel.text = @"未选择";
                        cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                    }else {
                        cell.subTitleLabel.text = _loanLifeName;
                    }
                }
            }
        }else {
            if (indexPath.row == 5) {
                cell.subTiltleTF.hidden = YES;
                NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                
                CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                label.textAlignment = NSTextAlignmentRight;
                label.text = @"元";
                label.font = [UIFont systemFontOfSize:15];
                [cell addSubview:label];
                
                _fundLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                _fundLoanTextField.delegate = self;
                _fundLoanTextField.returnKeyType =UIReturnKeyDone;
                _fundLoanTextField.textAlignment = NSTextAlignmentRight;
                _fundLoanTextField.font = [UIFont systemFontOfSize:15];
                _fundLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;
                [cell addSubview:_fundLoanTextField];

                if ([NSString isStringEmpty2:_fundLoan] == YES) {
                    _fundLoanTextField.placeholder = @"请输入";
                    
                }else {
                    _fundLoanTextField.text = _fundLoan;
                }
                
                
            }else if (indexPath.row == 6) {
                cell.subTiltleTF.hidden = YES;
                NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
                
                CGSize textSize = [@"元" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-textSize.width-10, 10, textSize.width, 30)];
                label.textAlignment = NSTextAlignmentRight;
                label.text = @"元";
                label.font = [UIFont systemFontOfSize:15];
                [cell addSubview:label];
                
                _businessLoanTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-textSize.width-15, 10, 200, 30)];
                _businessLoanTextField.delegate = self;
                _businessLoanTextField.returnKeyType =UIReturnKeyDone;
                _businessLoanTextField.textAlignment = NSTextAlignmentRight;
                _businessLoanTextField.font = [UIFont systemFontOfSize:15];
                _businessLoanTextField.keyboardType = UIKeyboardTypeDecimalPad;

                [cell addSubview:_businessLoanTextField];

                if ([NSString isStringEmpty2:_businessLoan] == YES) {
                    _businessLoanTextField.placeholder = @"请输入";
                }else {
                    _businessLoanTextField.text = _businessLoan;
                }
                
            }else if (indexPath.row == 7) {
                cell.subTitleLabel.hidden = NO;
                cell.btn_qiaoJImageV.hidden = NO;
                cell.subTiltleTF.hidden = YES;
                lineImage.hidden = YES;
                UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10)];
                v1.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
//                [cell addSubview:v1];
                
                UIImageView *lineIm = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                lineIm.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [cell addSubview:lineIm];
                
                if ([NSString isStringEmpty2:_loanRate] == YES) {
                    cell.subTitleLabel.text = @"未选择";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                }else {
                    cell.subTitleLabel.text = _loanRate;
                }
            }else if (indexPath.row == 8) {
                if ([NSString isStringEmpty2:_businessLoanRate] == YES) {
                    cell.subtitleOneLable.text = @"%";
                }else {
                    NSString *s = @"%";
                    cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_businessLoanRate,s];
                }
            }else if (indexPath.row == 9) {
            
                if ([NSString isStringEmpty2:_fundLoanRate] == YES) {
                    cell.subtitleOneLable.text = @"%";
                }else {
                    NSString *s = @"%";
                    cell.subtitleOneLable.text =[NSString stringWithFormat:@"%@%@",_fundLoanRate,s];
                }
            }else if (indexPath.row == 10) {
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = NO;
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_loanLifeName] == YES) {
                    cell.subTitleLabel.text = @"未选择";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                }else {
                    cell.subTitleLabel.text = _loanLifeName;
                }
            }
        }
    }
    return cell;
}


#pragma mark - 点击单项cell触发事件
/**
 *  功能描述：
 *  点击单项cell触发选择
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        ShoufuViewController *evc = [[ShoufuViewController alloc] init];
        evc.totalAmount = _totalAmount;
        [self.navigationController pushViewController:evc animated:YES];
        [evc setShoufuBlock:^(NSString *num1) {
            if ([NSString isStringEmpty2:num1] == NO) {
                float f = [num1 intValue];
                _firstPay = [NSString stringWithFormat:@"%.2f",f];
            }
            [_calculatePriceTableView reloadData];
        }];
    }else if (indexPath.row == 4) {
        _loanRate = @"";
        _fundLoanRate = @"";
        _businessLoanRate = @"";
        _fundLoan = @"";
        _businessLoan = @"";
        _loanTypeName = @"";
        _loanType = @"";
        //1、组合贷款；2、公积金贷款；3、商业贷款
        NSArray *arr = [NSArray arrayWithObjects:@"组合贷款",@"公积金贷款",@"商业贷款",nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block CalculatePriceViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
            NSLog(@"%@",indet);
            if ([NSString isStringEmpty2:indet] == NO) {
                
                _loanTypeName = indet;
                _loanType = numberString;
                if ([_loanTypeName isEqualToString:@"组合贷款"]) {
                    _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                                 @"房源总价",@"首付",@"贷款类型",@"公积金贷款",@"商业贷款",
                                 @"贷款利率",@"商业贷款利率",@"公积金贷款利率", @"贷款年限",nil];
                    [_calculateDic setValue:_grouparr0 forKey:@"0"];
                    
                }else if ([_loanTypeName isEqualToString:@"公积金贷款"]) {
                    _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                                 @"房源总价",@"首付",@"贷款类型",@"公积金贷款",@"贷款利率",@"公积金贷款利率", @"贷款年限",nil];
                    [_calculateDic setValue:_grouparr0 forKey:@"0"];
                    
                }else if ([_loanTypeName isEqualToString:@"商业贷款"]) {
                    _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                                 @"房源总价",@"首付",@"贷款类型",@"商业贷款",
                                 @"贷款利率",@"商业贷款利率",@"贷款年限",nil];
                    [_calculateDic setValue:_grouparr0 forKey:@"0"];
                }else {
                    _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                                 @"房源总价",@"首付",@"贷款类型",@"公积金贷款",@"商业贷款",
                                 @"贷款利率",@"商业贷款利率",@"公积金贷款利率", @"贷款年限",nil];
                    [_calculateDic setValue:_grouparr0 forKey:@"0"];
                }
            }else {
                _grouparr0 = [[NSMutableArray alloc] initWithObjects:@"客户姓名",@"联系电话",
                             @"房源总价",@"首付",@"贷款类型",@"公积金贷款",@"商业贷款",
                             @"贷款利率",@"商业贷款利率",@"公积金贷款利率", @"贷款年限",nil];
                [_calculateDic setValue:_grouparr0 forKey:@"0"];
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.calculatePriceTableView reloadData];
        }];
    }else {
        if ([NSString isStringEmpty2:_loanTypeName] == NO) {
            if ([_loanTypeName isEqualToString:@"组合贷款"]) {
                if (indexPath.row == 7) {
                   
                    LendingRateViewController *evc = [[LendingRateViewController alloc] init];
                    evc.isTpye = @"0";
                    [self.navigationController pushViewController:evc animated:YES];
                    [evc setLendingRateBlock:^(NSString *str1, NSString *str2, NSString *str3, NSString *str4) {
                        _loanRate = str1;
                        _businessLoanRate = str2;
                        _fundLoanRate = str3;
                        _beishuString = str4;
                        [_calculatePriceTableView reloadData];
                    }];
                    
                }else if (indexPath.row == 10) {
                    NSArray *arr = [NSArray arrayWithObjects:
                                    @"1年(12期)",@"2年(24期)",@"3年(36期)",@"4年(48期)",@"5年(60期)",
                                    @"6年(72期)",@"7年(84期)",@"8年(96期)",@"9年(108期)",@"10年(120期)",
                                    @"11年(132期)",@"12年(144期)",@"13年(156期)",@"14年(168期)",@"15年(180期)",
                                    @"16年(192期)",@"17年(204期)",@"18年(216期)",@"19年(228期)",@"20年(240期)",
                                    @"21年(252期)",@"22年(264期)",@"23年(276期)",@"24年(288期)",@"25年(300期)",
                                    @"26年(312期)",@"27年(324期)",@"28年(336期)",@"29年(348期)",@"30年(360期)",nil];
                    NSArray *arr1 = [NSArray arrayWithObjects:
                                     @"12",@"24",@"36",@"48",@"60",
                                     @"72",@"84",@"96",@"108",@"120",
                                     @"132",@"144",@"156",@"168",@"180",
                                     @"192",@"204",@"216",@"228",@"240",
                                     @"252",@"264",@"276",@"288",@"300",
                                     @"312",@"324",@"336",@"348",@"360",nil];
                    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
                    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                    __block ShowMenuView *weakMenuView = menuView;
                    __block CalculatePriceViewController *blockSelf = self;
                    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
                        NSLog(@"%@",indet);
                        if ([NSString isStringEmpty2:indet]== NO) {
                            _loanLifeName = indet;
                            NSString *str = [arr1 objectAtIndex:[numberString intValue] -1];
                            _loanLife = str;
                        }
                        [weakMenuView removeFromSuperview];
                        [blockSelf.calculatePriceTableView reloadData];
                    }];
                }

            }else if ([_loanTypeName isEqualToString:@"公积金贷款"]) {
                if (indexPath.row == 6) {
                    LendingRateViewController *evc = [[LendingRateViewController alloc] init];
                    evc.isTpye = @"1";
                    [self.navigationController pushViewController:evc animated:YES];
                    [evc setLendingRateBlock:^(NSString *str1, NSString *str2, NSString *str3,NSString *str4) {
                        _loanRate = str1;
                        _businessLoanRate = str2;
                        _fundLoanRate = str3;
                        _beishuString = str4;
                        [_calculatePriceTableView reloadData];
                    }];
                    
                }else if (indexPath.row == 8) {
                    NSArray *arr = [NSArray arrayWithObjects:
                                    @"1年(12期)",@"2年(24期)",@"3年(36期)",@"4年(48期)",@"5年(60期)",
                                    @"6年(72期)",@"7年(84期)",@"8年(96期)",@"9年(108期)",@"10年(120期)",
                                    @"11年(132期)",@"12年(144期)",@"13年(156期)",@"14年(168期)",@"15年(180期)",
                                    @"16年(192期)",@"17年(204期)",@"18年(216期)",@"19年(228期)",@"20年(240期)",
                                    @"21年(252期)",@"22年(264期)",@"23年(276期)",@"24年(288期)",@"25年(300期)",
                                    @"26年(312期)",@"27年(324期)",@"28年(336期)",@"29年(348期)",@"30年(360期)",nil];
                    NSArray *arr1 = [NSArray arrayWithObjects:
                                     @"12",@"24",@"36",@"48",@"60",
                                     @"72",@"84",@"96",@"108",@"120",
                                     @"132",@"144",@"156",@"168",@"180",
                                     @"192",@"204",@"216",@"228",@"240",
                                     @"252",@"264",@"276",@"288",@"300",
                                     @"312",@"324",@"336",@"348",@"360",nil];
                    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
                    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                    __block ShowMenuView *weakMenuView = menuView;
                    __block CalculatePriceViewController *blockSelf = self;
                    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
                        NSLog(@"%@",indet);
                        if ([NSString isStringEmpty2:indet]== NO) {
                            _loanLifeName = indet;
                            NSString *str = [arr1 objectAtIndex:[numberString intValue] -1];
                            _loanLife = str;
                        }
                        [weakMenuView removeFromSuperview];
                        [blockSelf.calculatePriceTableView reloadData];
                    }];
                }

            }else if ([_loanTypeName isEqualToString:@"商业贷款"]) {
                if (indexPath.row == 6) {
                    LendingRateViewController *evc = [[LendingRateViewController alloc] init];
                    evc.isTpye = @"2";
                    [self.navigationController pushViewController:evc animated:YES];
                    [evc setLendingRateBlock:^(NSString *str1, NSString *str2, NSString *str3,NSString *str4) {
                        _loanRate = str1;
                        _businessLoanRate = str2;
                        _fundLoanRate = str3;
                        _beishuString = str4;
                        [_calculatePriceTableView reloadData];
                    }];
                    
                }else if (indexPath.row == 8) {
                    NSArray *arr = [NSArray arrayWithObjects:
                                    @"1年(12期)",@"2年(24期)",@"3年(36期)",@"4年(48期)",@"5年(60期)",
                                    @"6年(72期)",@"7年(84期)",@"8年(96期)",@"9年(108期)",@"10年(120期)",
                                    @"11年(132期)",@"12年(144期)",@"13年(156期)",@"14年(168期)",@"15年(180期)",
                                    @"16年(192期)",@"17年(204期)",@"18年(216期)",@"19年(228期)",@"20年(240期)",
                                    @"21年(252期)",@"22年(264期)",@"23年(276期)",@"24年(288期)",@"25年(300期)",
                                    @"26年(312期)",@"27年(324期)",@"28年(336期)",@"29年(348期)",@"30年(360期)",nil];
                    NSArray *arr1 = [NSArray arrayWithObjects:
                                     @"12",@"24",@"36",@"48",@"60",
                                     @"72",@"84",@"96",@"108",@"120",
                                     @"132",@"144",@"156",@"168",@"180",
                                     @"192",@"204",@"216",@"228",@"240",
                                     @"252",@"264",@"276",@"288",@"300",
                                     @"312",@"324",@"336",@"348",@"360",nil];
                    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
                    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                    __block ShowMenuView *weakMenuView = menuView;
                    __block CalculatePriceViewController *blockSelf = self;
                    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
                        NSLog(@"%@",indet);
                        if ([NSString isStringEmpty2:indet]== NO) {
                            _loanLifeName = indet;
                            NSString *str = [arr1 objectAtIndex:[numberString intValue] -1];
                            _loanLife = str;
                        }
                        [weakMenuView removeFromSuperview];
                        [blockSelf.calculatePriceTableView reloadData];
                    }];
                }

            }else {
                if (indexPath.row == 7) {
                    LendingRateViewController *evc = [[LendingRateViewController alloc] init];
                    evc.isTpye = @"0";
                    [self.navigationController pushViewController:evc animated:YES];
                    [evc setLendingRateBlock:^(NSString *str1, NSString *str2, NSString *str3, NSString *str4) {
                        _loanRate = str1;
                        _businessLoanRate = str2;
                        _fundLoanRate = str3;
                        _beishuString = str4;
                        [_calculatePriceTableView reloadData];
                    }];
                    
                }else if (indexPath.row == 10) {
                    NSArray *arr = [NSArray arrayWithObjects:
                                    @"1年(12期)",@"2年(24期)",@"3年(36期)",@"4年(48期)",@"5年(60期)",
                                    @"6年(72期)",@"7年(84期)",@"8年(96期)",@"9年(108期)",@"10年(120期)",
                                    @"11年(132期)",@"12年(144期)",@"13年(156期)",@"14年(168期)",@"15年(180期)",
                                    @"16年(192期)",@"17年(204期)",@"18年(216期)",@"19年(228期)",@"20年(240期)",
                                    @"21年(252期)",@"22年(264期)",@"23年(276期)",@"24年(288期)",@"25年(300期)",
                                    @"26年(312期)",@"27年(324期)",@"28年(336期)",@"29年(348期)",@"30年(360期)",nil];
                    NSArray *arr1 = [NSArray arrayWithObjects:
                                     @"12",@"24",@"36",@"48",@"60",
                                     @"72",@"84",@"96",@"108",@"120",
                                     @"132",@"144",@"156",@"168",@"180",
                                     @"192",@"204",@"216",@"228",@"240",
                                     @"252",@"264",@"276",@"288",@"300",
                                     @"312",@"324",@"336",@"348",@"360",nil];
                    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
                    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                    __block ShowMenuView *weakMenuView = menuView;
                    __block CalculatePriceViewController *blockSelf = self;
                    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
                        NSLog(@"%@",indet);
                        if ([NSString isStringEmpty2:indet]== NO) {
                            _loanLifeName = indet;
                            NSString *str = [arr1 objectAtIndex:[numberString intValue] -1];
                            _loanLife = str;
                        }
                        [weakMenuView removeFromSuperview];
                        [blockSelf.calculatePriceTableView reloadData];
                    }];
                }

            }
        }else {
            if (indexPath.row == 7) {
                if (_loanTypeName.length == 0) {
                    [self showToast:@"请先选择贷款类型"];
                    return;
                }
                LendingRateViewController *evc = [[LendingRateViewController alloc] init];
                evc.isTpye = @"0";
                [self.navigationController pushViewController:evc animated:YES];
                [evc setLendingRateBlock:^(NSString *str1, NSString *str2, NSString *str3,NSString *str4) {
                    _loanRate = str1;
                    _businessLoanRate = str2;
                    _fundLoanRate = str3;
                    _beishuString = str4;
                    [_calculatePriceTableView reloadData];
                }];
                
            }else if (indexPath.row == 10) {
                NSArray *arr = [NSArray arrayWithObjects:
                                @"1年(12期)",@"2年(24期)",@"3年(36期)",@"4年(48期)",@"5年(60期)",
                                @"6年(72期)",@"7年(84期)",@"8年(96期)",@"9年(108期)",@"10年(120期)",
                                @"11年(132期)",@"12年(144期)",@"13年(156期)",@"14年(168期)",@"15年(180期)",
                                @"16年(192期)",@"17年(204期)",@"18年(216期)",@"19年(228期)",@"20年(240期)",
                                @"21年(252期)",@"22年(264期)",@"23年(276期)",@"24年(288期)",@"25年(300期)",
                                @"26年(312期)",@"27年(324期)",@"28年(336期)",@"29年(348期)",@"30年(360期)",nil];
                NSArray *arr1 = [NSArray arrayWithObjects:
                                 @"12",@"24",@"36",@"48",@"60",
                                 @"72",@"84",@"96",@"108",@"120",
                                 @"132",@"144",@"156",@"168",@"180",
                                 @"192",@"204",@"216",@"228",@"240",
                                 @"252",@"264",@"276",@"288",@"300",
                                 @"312",@"324",@"336",@"348",@"360",nil];
                ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
                menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                __block ShowMenuView *weakMenuView = menuView;
                __block CalculatePriceViewController *blockSelf = self;
                [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
                    NSLog(@"%@",indet);
                    if ([NSString isStringEmpty2:indet]== NO) {
                        _loanLifeName = indet;
                        NSString *str = [arr1 objectAtIndex:[numberString intValue] -1];
                        _loanLife = str;
                    }
                    [weakMenuView removeFromSuperview];
                    [blockSelf.calculatePriceTableView reloadData];
                }];
            }
        }
    }
}

#pragma mark - 跳转选择客户列表
/**
 *  功能描述：
 *  选择客户加入算价界面
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
- (void)seleBtnClick:(UIButton *)btn {
    if (_isseleFals == YES) {
        EMMTouristsViewController *evc = [[EMMTouristsViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        evc.tourSring = @"4";
        evc.titleString = @"算价客户";
        evc.suanjiaTpye = @"1";
        [self.navigationController pushViewController:evc animated:YES];
        [evc setTouristsBlock:^(NSMutableArray *dataArr) {
            CustomerList *list = [dataArr objectAtIndex:0];
            _khString = list.customerName;
            _phonString = list.mobile;
            _isSeleId = @"1";
            _customerId = list.customerId;
            [_calculatePriceTableView reloadData];
        }];
        _isseleFals = NO;
    }else {
        _khString = nil;
        _phonString = nil;
        _isSeleId = nil;
        _customerId = nil;
        [_calculatePriceTableView reloadData];
        _isseleFals = YES;
    }
}

#pragma mark - 二级列表展开调用方法
/**
 *  功能描述：
 *  二级列表展开收起功能
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
-(void)doButton:(UIButton *)sender {
    NSString *string = [NSString stringWithFormat:@"%ld",sender.tag-100];
    //数组selectedArr里面存的数据和表头想对应，方便以后做比较
    if ([_selectedArr containsObject:string]) {
        [_selectedArr removeObject:string];
    } else  {
        [_selectedArr addObject:string];
    }
    [_calculatePriceTableView reloadData];
}

#pragma mark - UITextField 代理调用方法
/**
 *  功能描述：
 *  UItextField的代理方法
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
-(void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == _khTextField) {
        if (textField.text.length > 10) {
            [self showToast:@"输入不能超过10位，请重新输入"];
            [_calculatePriceTableView reloadData];
            return;
        }
        _khString = textField.text;
    }else if (textField == _phonTextField) {
        if (textField.text.length == 11) {
            if (![textField.text isMobileNumberClassification]) {
                [self showToast:@"请输入正确的手机号"];
            }else {
                _phonString = textField.text;
            }
        }else {
            [self showToast:@"输入手机号位数不对"];
        }
    }else if (textField == _totalAmountTextField) {
        _totalAmount = textField.text;
    }else if (textField == _fundLoanTextField) {
        _fundLoan = textField.text;
        if ([_loanType isEqualToString:@"2"]) {
            float zj = [_totalAmount floatValue] - [_firstPay floatValue];
            float gj = [_fundLoan floatValue];
            if (gj > zj) {
                _fundLoan = @"";
                [self showToast:@"贷款金额不能高于未付金额"];
                [_calculatePriceTableView reloadData];
                return;
            }
        }else if ([_loanType isEqualToString:@"3"]) {
            
        }else if([_loanType isEqualToString:@"1"]) {
            float zj = [_totalAmount floatValue] - [_firstPay floatValue];
            float gj = [_fundLoan floatValue];
            float sy = [_businessLoan floatValue];
            if (sy+gj > zj) {
                _fundLoan = @"";
                [self showToast:@"贷款金额不能高于未付金额"];
                [_calculatePriceTableView reloadData];
                return;
            }
        }
    }else if (textField == _businessLoanTextField) {
        _businessLoan = textField.text;
        if ([_loanType isEqualToString:@"2"]) {
            
        }else if ([_loanType isEqualToString:@"3"]) {
            float zj = [_totalAmount floatValue] - [_firstPay floatValue];
            float sy = [_businessLoan floatValue];
            if (sy > zj) {
                _fundLoan = @"";
                [self showToast:@"贷款金额不能高于未付金额"];
                [_calculatePriceTableView reloadData];
                return;
            }
        }else if([_loanType isEqualToString:@"1"]) {
            float zj = [_totalAmount floatValue] - [_firstPay floatValue];
            float gj = [_fundLoan floatValue];
            float sy = [_businessLoan floatValue];
            if (sy+gj > zj) {
                _fundLoan = @"";
                [self showToast:@"贷款金额不能高于未付金额"];
                [_calculatePriceTableView reloadData];
                return;
            }
        }
    }
    [_calculatePriceTableView reloadData];
}

#pragma mark - 开始算价按钮事件调用方法
/**
 *  功能描述：
 *  算价按钮点击触发方法
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
- (void)startButtonClick:(UIButton *)btn {
    if ([NSString isStringEmpty:_firstPay] == YES) {
        [self showToast:@"首付不能为空"];
        return;
    }
    if ([NSString isStringEmpty:_loanType] == YES) {
        [self showToast:@"贷款类型未选择"];
        return;
    }
    NSString *str1;
    NSString *str2;
    NSString *str3;
    NSString *str4;
    if ([_loanType isEqualToString:@"2"]) {
        if ([NSString isStringEmpty2:_fundLoan] == YES) {
            [self showToast:@"公积金贷款未输入"];
            return;
        }
        str1 = _fundLoan;
        str3 = _fundLoanRate;
        str2 = @"";
        str4 = @"";
    }else if ([_loanType isEqualToString:@"3"]) {
        if ([NSString isStringEmpty2:_businessLoan] == YES) {
            [self showToast:@"商业贷款未输入"];
            return;
        }
        str1 = @"";
        str3 = @"";
        str2 = _businessLoan;
        str4 = _businessLoanRate;
    }else if([_loanType isEqualToString:@"1"]) {
        if ([NSString isStringEmpty2:_fundLoan] == YES) {
            [self showToast:@"公积金贷款未输入"];
            return;
        }
        if ([NSString isStringEmpty2:_businessLoan] == YES) {
            [self showToast:@"商业贷款未输入"];
            return;
        }
        str1 = _fundLoan;
        str3 = _fundLoanRate;
        str2 = _businessLoan;
        str4 = _businessLoanRate;
    }
    if ([NSString isStringEmpty:_loanRate] == YES) {
        [self showToast:@"贷款利率未选择"];
        return;
    }
    if ([NSString isStringEmpty:_loanLife] == YES) {
        [self showToast:@"贷款年限未选择"];
        return;
    }
    if ([_isSeleId isEqualToString:@"1"]) {
        NSString *titel = [NSString stringWithFormat:@"是否将%@,标记为%@的意向房源",[_getHousesDetail.housesName stringByReplacingOccurrencesOfString:@"-->"withString:@"-"],_khString];
        PromptBoxView *userListV = [[PromptBoxView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT) done:@"是" clan:@"否" titleString:titel];
        userListV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:userListV];
        __block PromptBoxView *weakMenuView = userListV;
        __block CalculatePriceViewController *blockSelf = self;
        [userListV setPromptBoxViewBlock:^(NSString *tpye) {
            if ([tpye isEqualToString:@"1"]) {
                [blockSelf postGetCalculatePriceApistr1:str1 str2:str2 str3:str3 str4:str4 str5:_customerId];
            }else {
                [blockSelf postGetCalculatePriceApistr1:str1 str2:str2 str3:str3 str4:str4 str5:nil];
            }
            [weakMenuView removeFromSuperview];
        }];
    }else {
        [self postGetCalculatePriceApistr1:str1 str2:str2 str3:str3 str4:str4 str5:nil];
    }
}

#pragma mark - 开始算价Api调用方法
/**
 *  功能描述：
 *  获取算价结果的Api接口
 *  更新时间：2016/12/22
 *  更新人：wangguiping
 */
- (void)postGetCalculatePriceApistr1:(NSString *)str1
                                str2:(NSString *)str2
                                str3:(NSString *)str3
                                str4:(NSString *)str4
                                str5:(NSString *)str5{
    [self showHud:@"正在加载请稍等..."];
    GetCalculatePriceApi *api = [[GetCalculatePriceApi alloc] initWithRroomId:_roomId
                                                               housesSumPrice:_totalAmount
                                                                     firstPay:_firstPay
                                                                     loanType:_loanType
                                                                     fundLoan:str1
                                                                 businessLoan:str2
                                                                     loanRate:_loanRate
                                                                 fundLoanRate:str3
                                                             businessLoanRate:str4
                                                                     loanLife:_loanLife
                                                                   customerId:str5];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetCalculatePriceApi *result = (GetCalculatePriceApi *)request;
        if (result.isSuccess) {
            GetCalculatePrice *get = result.resultData;
            PriceResultViewController *pvc = [[PriceResultViewController alloc] init];
            pvc.getCalculatePrice = get;
            pvc.getHousesDetail = _getHousesDetail;
            pvc.khString = _khString;
            pvc.phonString = _phonString;
            pvc.fundLoanRate = _fundLoanRate;
            pvc.businessLoanRate = _businessLoanRate;
            pvc.beishuString = _beishuString;
            pvc.loanTypeName = _loanTypeName;
            [self.navigationController pushViewController:pvc animated:YES];
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }                                                                   
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

@end
